package com.bocai.service.impl;

import com.bocai.bean.CardInfo;
import com.bocai.mapper.CardInfoMapper;
import com.bocai.service.ICardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class CardInfoServiceImpl implements ICardService {
    @Autowired
    private CardInfoMapper cardInfoMapper;

    @Override
    public CardInfo selectCardInfo(BigDecimal cardMoney) {
        return cardInfoMapper.selectByMoney(cardMoney);
    }

    @Override
    public CardInfo selectCardInfo() {
        return cardInfoMapper.selectCardInFo();
    }

    @Override
    public int updateCardInfo(BigDecimal cardMoney, BigDecimal cardRewardMoney, Integer cardState) {
        CardInfo cardInfo = cardInfoMapper.selectCardInFo();
        if (null != cardInfo) {
            Map<String, Object> map = new HashMap<>();
            map.put("cardMoney", cardMoney);
            map.put("cardId", cardInfo.getCardId());
            map.put("cardRewardMoney", cardRewardMoney);
            map.put("cardState", cardState);
            return cardInfoMapper.updateByMoney(map);
        } else {
            CardInfo cardInfo1 = new CardInfo();
            cardInfo1.setCardRewardMoney(cardRewardMoney);
            cardInfo1.setCardNumber("111111");
            cardInfo1.setCardMoney(cardMoney);
            cardInfo1.setCreateTime(new Date());
            cardInfo1.setCardState(cardState);
            cardInfo1.setCardCount("描述");
            return cardInfoMapper.insertSelective(cardInfo1);
        }
    }
}
